import subjectApi from '@/api/subject'

const state = {
  subjects: []
}

const getters = {
  subjectEnumFormat: (state) => (array, key) => {
    for (let item of array) {
      if (item.id == key) {
        return item.name
      }
    }
    return null
  }
}

// actions
const actions = {
  initSubject ({ commit }) {
    subjectApi.list().then(re => {
      console.log(re);
      commit('setSubjects', re.response)
    })
  }
}

// mutations
const mutations = {
  setSubjects: (state, subjects) => {
    state.subjects = subjects
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
